class Solution
{
public:
    int passThePillow(int n, int time)
    {
        bool direction = true;
        int pos = 1;
        while (time)
        {
            if (direction)
            {
                ++pos;
                if (pos == n)
                {
                    direction = !direction;
                }
            }
            else
            {
                --pos;
                if (pos == 1)
                {
                    direction = !direction;
                }
            }
            --time;
        }
        return pos;
    }
};